/**
 * (c) Copyright Ascensio System SIA 2025
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.hulman.oms.office.controller;

import com.hulman.oms.util.CodeGenerator;
import com.onlyoffice.manager.url.UrlManager;
import com.onlyoffice.model.documenteditor.Config;
import com.onlyoffice.model.documenteditor.config.document.Type;
import com.onlyoffice.model.documenteditor.config.editorconfig.Mode;
import com.onlyoffice.service.documenteditor.config.ConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
@Slf4j
public class PageController
{
    @Autowired
    private ConfigService configService;
    @Autowired
    private UrlManager urlManager;

    @GetMapping("/office-editor")
    public String editor(String fileId, final Model model)
    {
        Config config = configService.createConfig(fileId, Mode.EDIT, Type.DESKTOP);
        //config.getEditorConfig().setLang("zh");
        model.addAttribute("config", config);
        model.addAttribute("documentServerApiUrl", urlManager.getDocumentServerApiUrl());
        return "office";
    }

    @GetMapping("/office-viewer")
    public String viewer(String fileId, final Model model)
    {
        Config config = configService.createConfig(fileId, Mode.VIEW, Type.DESKTOP);
        //config.getEditorConfig().setLang("zh");
        model.addAttribute("config", config);
        model.addAttribute("documentServerApiUrl", urlManager.getDocumentServerApiUrl());
        return "office";
    }

}
